﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fall.Core.BaseModels
{
    /// <summary>
    /// 通用返回结果
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class CommonResult<T>
    {
        public CommonResult(string code, T result, bool isSuccess, ErrorResult errorResult) 
        {
            Code = code;
            Result = result;
            IsSuccess = isSuccess;
            ErrorResult = errorResult;
        }
        /// <summary>
        /// 自定义状态码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 是否成功(true or false)
        /// </summary>
        public bool IsSuccess { get; set; }
        /// <summary>
        /// 返回结果
        /// </summary>
        public T Result { get; set; }
        /// <summary>
        /// 错误结果
        /// </summary>
        public ErrorResult ErrorResult { get; set; }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="code">状态码</param>
        /// <param name="result">返回结果</param>
        /// <returns></returns>
        public static CommonResult<T> Success(string code, T result) 
        {
            return new CommonResult<T>(code,result,true,null);
        }
        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="code">状态码</param>
        /// <param name="errorResult">错误结果</param>
        /// <returns></returns>
        public static CommonResult<T> Error(string code, ErrorResult errorResult) 
        {
            return new CommonResult<T>(code, default(T), false, errorResult);
        }
    }
    /// <summary>
    /// 错误信息
    /// </summary>
    public class ErrorResult
    {
        /// <summary>
        /// 错误信息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 错误详情
        /// </summary>
        public string Detail { get; set; }
    }
}
